package Controler;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Information.CV;
import Information.UserInfo;
import Model.CVDAO;
import Model.UserInfomrmationDAO;

public class managePerson extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public managePerson() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		ArrayList<UserInfo> personArrayList = new ArrayList<UserInfo>();
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String UUser = null;
		String UPassword = null;
		String UEmail = null;
		String UName = null;
		UserInfomrmationDAO persondao = new UserInfomrmationDAO();
		try {
			personArrayList = persondao.SeeAllUser();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String result = "";
		for(UserInfo person : personArrayList)
		{
			result+="<div class='panel panel-primary'>";
			result+="<form role='form' id='PersonForm' method='post' action='updateCVNow'>";
			result+="<div class='form-group' id='UUserDiv'><label for='UUser'>用户名</label><input type='text' class='form-control' id='UUser' name='UUser' value='"+person.getUUser()+"' disabled></div>";
			result+="<div class='form-group' id='UPasswordDiv'><label for='UPassword'>密码</label><input type='text' class='form-control' id='UPassword' name='UPassword' value='"+person.getUPassword()+"'></div>";
			result+="<div class='form-group' id='UNameDiv'><label for='UName'>真实姓名</label><input type='text' class='form-control' id='UName' name='UName' value='"+person.getUName()+"'></div>";
			result+="<div class='form-group' id='UEmailDiv'><label for='UEmail'>邮箱</label><input type='text' class='form-control' id='UEmail' name='UEmail' value='"+person.getUEmail()+"'></div>";
			result+="<div class='form-group' id='updateDiv'><a class='btn btn-success' id='updatePerson' type='button'>更新</a></div>";
			result+="<div class='form-group' id='deleteDiv'><a class='btn btn-danger' id='deletePerson' type='button'>删除</a></div></form></div>";
		}
		out.println(result);
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
